/*
** my_xfunc.c for my_xfunc in /home/le_e//project/BSQ/bsq2
** 
** Made by canh-kiet le
** Login   <le_e@epitech.net>
** 
** Started on  Wed Dec  7 21:51:14 2011 canh-kiet le
** Last update Sun Apr 29 16:27:05 2012 canh-kiet le
*/

#include	"my.h"


void		*xmalloc(int size)
{
  void		*s;

  if ((s = malloc(size)) == NULL)
    {
      print_err("ERROR on malloc\n");
      exit(EXIT_FAILURE);
    }
  return (s);
}

int		xclose(int fd)
{
  int		ret;

  if ((ret = close(fd)) == -1)
    {
      print_err("ERROR on close\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}

int             xopen(char *pathname, int flags)
{
  int           fd;
  
  if ((fd = open(pathname, flags)) == -1)
    {
      print_err("ERROR on open\n");
      exit(EXIT_FAILURE);
    }
  return (fd);
}

int		xread(int fd, char *buff, int nb)
{
  int		ret;

  if ((ret = read(fd, buff, nb)) == -1)
    {
      print_err("ERROR on read\n");
      exit(EXIT_FAILURE);
    }
  return (ret);
}

int		xwrite(int fd, char *s, int len)
{
  int		nb;

  if ((nb = write(fd, s, len)) == -1)
    exit(EXIT_FAILURE);
  return (nb);
}
